#!/usr/bin/env python
# -*- coding: utf_8 -*-

#    guteninja: a frontend for various video-games
#    Copyright (C) 2007  Tor-björn Claesson

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

class game:

    def _get_gamename(self):
        return self._gamename
    def _set_gamename(self, gamename):
        self._gamename = gamename
    gamename = property(_get_gamename, _set_gamename)

    def _get_gamesystem(self):
        return self._gamesystem
    def _set_gamesystem(self, gamesystem):
        self._gamesystem = gamesystem
    gamesystem = property(_get_gamesystem, _set_gamesystem)
	
    def _get_romfile(self):
        return self._romfile
    def _set_romfile(self, romfile):
        self._romfile = romfile
    romfile = property(_get_romfile, _set_romfile)
	
    def _get_max_players(self):
        return self._max_players
    def _set_max_players(self, max_players):
        self._max_players = max_players
    max_players = property(_get_max_players, _set_max_players)
	
    def _get_image(self):
        return self._image
    def _set_image(self, image):
        self._image = image
    image = property(_get_image, _set_image)
	
    def _get_description(self):
        return self._description
    def _set_description(self, description):
        self._description = description
    description = property(_get_description, _set_description)
	
    def _get_buttons():
        return self.buttons
    def _set_buttons(self, buttons):
        self.buttons = buttons
    buttons = property(_get_buttons, _set_buttons)

    def _get_args(self):
        return self._args
    def _set_args(self, args):
        self._args = args
    args = property(_get_args, _set_args)
    def _get_path(self):
        return self._path
    def _set_path(self, path):
        self._path = path
    path = property(_get_path, _set_path)
	
    def load_from_file(self, filename):

        #A dict with all the parameters in:
        options = {"gamename": None,
                "gamesystem": None,
                "romfile": None,
                "image": None,
                "max_players": None,
                "description": None,
                "buttons": None
                }

        #Open the file:
        filen = open(filename, 'r')

		#Parse the file:
        for string in filen:
            temporar_lista = string.strip('\n').split('=')
            options[temporar_lista[0]] = temporar_lista[1]

		#Save the values in the class
        self.gamename = options["gamename"]
        self.gamesystem = options["gamesystem"]
        self.romfile = options["romfile"]
        self.image = options["image"]
        self.max_players = options["max_players"]
        self.description = options["description"]
        self.buttons = options["buttons"]

    def save_to_file(self, filename):
        pass
	
    def __init__(self, gamename=None, gamesystem=None, romfile=None, image=None, max_players=None, description=None, buttons=None, from_file=None, path=None):
        if (from_file !=None):
            #Läs in allt från en fil
            self.load_from_file(path + from_file)
		
            #Skriv över eventuella parametrar som skickats med
            if (gamename != None):
                self.gamename=gamename
            if (gamesystem != None):
                self.gamesystem = gamesystem
            if (romfile != None):
                self.romfile = romfile
            if (image != None):
                self.image = image
            if (max_players != None):
                self.max_players = max_players
            if (description != None):
                self.description = description
            if (buttons != None):
                self.buttons = buttons
            if (path != None):
                self.path = path
			
        else:
            self.gamename=gamename
            self.gamesystem=gamesystem
            self.romfile=romfile
            self.image=image
            self.max_players=max_players
            self.description=description
            self.buttons=buttons
            self.path=path